<?php

class DbDateTimeField extends DbField {

    /**
     * @param string $dbName name in database
     * @param bool $null is null allowed ?
     */
    public function __construct($dbName,$null=true) {
        parent::__construct($dbName,$null);
    }

    public function toPhp($value) {
        return new DateTimeBean($value);
    }

    /**
     *
     */
    public function toDb($value) {
        // if null is not allowed, use NOW()
        if (is_null($value) and !$this->null)
            return 'NOW()';
        if (is_a($value,'DateTimeBean'))
            return "'".$value->toMysqlDateTime()."'";
        return 'NULL';
    }
}